import React from "react";
import {LinkProps} from "@ant-design/pro-layout/lib/typings";
import {PermissionProps} from "@/components/Permission/index";
import {connect} from "dva";
import {GlobalModelState} from "@/models/global";
import { Link } from "umi";

interface Props extends LinkProps,PermissionProps{

}

class LinkPermission extends React.Component<Props> {
  render() {
    const { functionKey,functions } = this.props;
    if(functionKey&&functions&&functions.some(item=>item.path===functionKey)){
      return (
        <Link {...this.props}>
          {this.props.children}
        </Link>
      );
    }
    return null;
  }
}

export default connect(({
                          global
                        }:{
  global: GlobalModelState;
}) => ({
  functions:global.profile.functions
}))(LinkPermission);
